// pages/searchMusic/searchMusic.js
const {get_searchMusic} = require("../../utils/ajax")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        musicList:[],
        page:0,
        searchKey:"",
        ishave:""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            searchKey:options.key
        })
        this.getSearchMusic()
    },
    getSearchMusic(){
        this.data.page++
        get_searchMusic({key:this.data.searchKey,pn:this.data.page,rn:10}).then(res=>{
            if(res.code==-1){
                this.setData({
                    ishave:"没有你要搜的歌曲"
                })
            }else{
                this.setData({
                    musicList:[...this.data.musicList,...res.data.list]
                })
            }
        })
    },
    onReachBottom:function(){
        this.getSearchMusic()
    }
})